package com.ruoyi.backstage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zzw.domain.Catalogue;
import com.ruoyi.zzw.service.TCatalogueService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

/**
 * 目录管理Controller
 * 
 * @author ruoyi
 * @date 2023-12-06
 */
@RestController
@RequestMapping("/backstage/catalogue")
public class BackCatalogueController extends BaseController
{
    @Autowired
    private TCatalogueService tCatalogueService;

    /**
     * 查询目录管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:catalogue:list')")
    @GetMapping("/list")
    public AjaxResult list(Catalogue catalogue)
    {

        List<Catalogue> list = tCatalogueService.selectTCatalogueList(catalogue);
        return success(list);
    }

    /**
     * 导出目录管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:catalogue:export')")
    @Log(title = "目录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Catalogue catalogue)
    {
        List<Catalogue> list = tCatalogueService.selectTCatalogueList(catalogue);
        ExcelUtil<Catalogue> util = new ExcelUtil<Catalogue>(Catalogue.class);
        util.exportExcel(response, list, "目录管理数据");
    }

    /**
     * 获取目录管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:catalogue:query')")
    @GetMapping(value = "/{cCatalogueId}")
    public AjaxResult getInfo(@PathVariable("cCatalogueId") Long cCatalogueId)
    {
        return success(tCatalogueService.selectTCatalogueByCCatalogueId(cCatalogueId));
    }

    /**
     * 新增目录管理
     */
    @PreAuthorize("@ss.hasPermi('system:catalogue:add')")
    @Log(title = "目录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Catalogue catalogue)
    {
        return toAjax(tCatalogueService.insertTCatalogue(catalogue));
    }

    /**
     * 修改目录管理
     */
    @PreAuthorize("@ss.hasPermi('system:catalogue:edit')")
    @Log(title = "目录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Catalogue catalogue)
    {
        return toAjax(tCatalogueService.updateTCatalogue(catalogue));
    }

    /**
     * 删除目录管理
     */
    @PreAuthorize("@ss.hasPermi('system:catalogue:remove')")
    @Log(title = "目录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cCatalogueIds}")
    public AjaxResult remove(@PathVariable Long[] cCatalogueIds)
    {
        return toAjax(tCatalogueService.deleteTCatalogueByCCatalogueIds(cCatalogueIds));
    }
}
